(function(){
    angular.module('app').controller("dspRecordCtrl",function($scope,proxy) {
        $scope.finance = {};
        $scope.ajaxData = {
            "filter":{
                "action":""
            },
            "sort": ['cTime,1'],
            "sTime": getNowFormatDate() + ' 00:00:00',
            "eTime": getNowFormatDate() + ' 23:59:59',
            "page": "1",
            "size": "20"
        }

        $scope.showData = {
            dealType: [{name: '全部类型'}, {id: 'deposit', name: 'Admin转入资金'}, {id: 'withdraw', name: 'Admin转出资金'},
                {id: 'agencyIn', name: '广告公司充值'},  {id: 'agencyOut', name: '广告公司提现'}, {id: 'rtbProfit', name: '提取利润'}, 
                {id:'purchase',name:"保价保量扣款"},{id:'receipts',name:"保价保量收入"}
            ],
            actionName: '交易类型'
        }

        $scope.showData.dealTypeObj = arrToObj($scope.showData.dealType)

        $scope.event = {
            selectType: function (item) {
                $scope.ajaxData.filter.action = item.id
                getList()
            },
            chooseDate: function (s, e) {
                $scope.ajaxData.sTime = s + " 00:00:00"
                $scope.ajaxData.eTime = e + " 23:59:59"
                getList()
            }
        }
        getList()
        getFinance();
        //获取列表
        function getList(current, pagesize) {
            $scope.ajaxData.page = (current || 1)+""
            $scope.ajaxData.size = (pagesize || 20)+""

            proxy.proxy({
                url: STATIC_URL.domian+'/dsp/saas/dsp/finace/list',
                load: true,
                data: $scope.ajaxData,
                success: function(res){
                    // 获得列表
                    $scope.list = res.data.data;
                    $("#pageToolbar").html("");
                    $('#pageToolbar').Paging({
                        pagesize: pagesize || '20',
                        current: current || '1',
                        count:res.data.total,
                        toolbar:true,
                        'hash': false,
                        callback:getList
                    });
                }
            })
        }
        function getFinance() {
            proxy.proxy({
                url: STATIC_URL.domian+'/dsp/saas/dsp/finace/summary',
                data: {},
                success: function(res){
                    $scope.finance = res.data;
                }
            })
        }
        //将数组转为key：Val对象
        function arrToObj(arr) {
            var obj = {}
            for (var i = 0; i < arr.length; i++) {
                obj[arr[i].id] = arr[i].name
            }
            return obj
        }
    })
})();